package thread;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class Demo18_CountDownLatch {
    public static void main(String[] args) throws InterruptedException {
        CountDownLatch latch = new CountDownLatch(10);
        ExecutorService executor = Executors.newFixedThreadPool(4);
        for(int i = 0; i < 10; ++i){
            int id = i;
            executor.submit(()->{
                System.out.println("子线程执行" + id);
                try{
                    Thread.sleep(1000);
                }catch (InterruptedException e){
                    throw new RuntimeException(e);
                }
                System.out.println("子线程结束执行" + id);
                latch.countDown();

            });
        }
        latch.await();
        System.out.println("执行完毕");
        executor.shutdown();
    }
}
